<?php

	class postData {
		
		protected $data;
		
		/**
		 *
		 * @var ADOConnection database connection
		 */
		protected $db;
		
		/**
		 *
		 * @var Smarty smarty instance pointer
		 */
		protected $smarty;

		/**
		 *
		 * @param type $action
		 * @param type $data
		 * @param ADOConnection $db
		 * 
		 * @return postData action handler instance
		 * 
		 */
		public static final function getSubmitActionInstance($action, $data, $db, &$smarty) {
			$className = 'postData' . ucfirst($action);
			if (file_exists(MUKU_DOC_ROOT . 'lib/postDataTypes/' . $className . '.class.php')) {
				require_once MUKU_DOC_ROOT . 'lib/postDataTypes/' . $className . '.class.php';
				$postDataType = new $className($data, $db, $smarty);				
				if ($postDataType instanceof $className) {
					return $postDataType;
				} else {
					return array	(	'result'	=> FALSE,
										'message'	=> 'no instance!'
									);
				}
			} else {
				return array	(	'result'	=> FALSE,
									'message'	=> 'class not found!'
								);
			}
		}
		
		public function __construct($data, $db, $smarty) {
			$this->data = $data;
			$this->db = &$db;
			$this->smarty = $smarty;
		}
		
		protected function processData() {
			// needs to be overridden
		}
		
		public function executeAction() {
			$status = $this->processData();
			$this->smarty->assign('action_response', $status['message']);
			return $status['result'];
		}
		
	}

?>
